//
//  ImageButton.swift
//  xgwjinterconnection
//
//  Created by WangWeiShuo on 2025/8/20.
//

import SwiftUI

struct ImageButton: View {
    // 跟踪按钮是否被按下
    @State private var isPressed = false
    
    // 自定义图片
    var defaultImage: String
    var pressedImage: String
    
    var body: some View {
        Image(isPressed ? pressedImage : defaultImage)
            .resizable()
            .scaledToFit()
            .padding()
            .scaleEffect(isPressed ? 0.9 : 1.0)
            .animation(.spring(), value: isPressed)
        // 监听按压状态变化
            .simultaneousGesture(
                DragGesture(minimumDistance: 0)
                    .onChanged { _ in
                        isPressed = true
                    }
                    .onEnded { _ in
                        isPressed = false
                    }
            )
    }
}
